<?php

class GalleryDAO extends BaseDAO {

    public function getAll(){
        $list ;
        $sql='SELECT * FROM `gallery` LIMIT 0,25 ;';
        $result = mysql_query($sql);
        while($row = mysql_fetch_object($result,'gallery')) {
            $list[] = $row;
        }
        return $list;
    }

    public function getById($id){
        $sql='SELECT * FROM `gallery` WHERE `id`= '.$id.';';
        $result = mysql_query($sql);
        return mysql_fetch_object($result,'gallery');
    }

    public function insert($gallery){
        $id=  false;
        $sql='INSERT INTO `gallery` (
        `title`,
        `description`,
        `defoultPhotoId`,
        `layout_id`,
        `created`) VALUES(
        \''.$gallery->title.'\',
        \''.$gallery->description.'\',
        \''.$gallery->defoultPhotoId.'\',
        \''.$gallery->layout_id.'\',
        NOW());';
        $result = mysql_query($sql);
        if($result){
            $id = mysql_insert_id();
        }
        return $id;
    }

    public function update($gallery){
        $sql='UPDATE `gallery` SET
        `title`=\''.$gallery->title.'\' ,
        `description`=\''.$gallery->description.'\',
        `defoultPhotoId`='.$gallery->defoultPhotoId.',
        `layout_id` ='.$gallery->layout_id.',
        `created` ='.$gallery->created.',
         WHERE `id`=\''.$gallery->id.'\' ;';
         $result = mysql_query($sql);
    }


    public function delete($id){
        $sql='DELETE FROM `gallery` WHERE `id`='.$id.';';
        $result = mysql_query($sql);
    }

    public function GalleryDAO(){
        $this->initDB();
    }

}
?>
